import request from "./request/request";

interface IUser {
    account: string;
    password: string;
}

interface ILogin extends IUser {
    captcha: string;
}

interface IUserResponse extends IUser {
    token: string;
}

interface ILoginResponse {
    data: IUserResponse
    code: number;
}

/**
 * 登录
 *
 * @param { ILogin } data
 */
export function login (data: ILogin): Promise<ILoginResponse> {
    return request.post('/authorize/login', data)
}

export function password (password: string, oldPwd: string) {
    return request.put('/authorize/password', { password, oldPwd }).catch(error => error)
}

export function register (data: IUser): Promise<ILoginResponse> {
    return request.post('/authorize/register', data).catch(error => error)
}

export function whoami () {
    return request.get('/authorize/whoami').catch(error => error)
}
